package com.gainloop.Api.Entity;

import java.io.Serializable;
import java.util.Date;

import com.gainloop.Api.ApiException;
import com.google.gson.annotations.SerializedName;

public class Wish extends EntityAbstract implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5754129256321594696L;

	

	public enum STATUS {
		OPEN,
		CANCELED,
		RESOLVED
	}

	@SerializedName("id")
	private long _id;

	@SerializedName("userId")
	private long _userId;

	@SerializedName("createTime")
	private long _createTime;

	@SerializedName("categoryId")
	private long _categoryId;
		
	@SerializedName("content")
	private String _content;
		
	@SerializedName("shortContent")
	private String _shortContent;
		
	@SerializedName("status")
	private int _status;

	@SerializedName("lastChangeTime")
	private long _lastChangeTime;

	@SerializedName("tagsNum")
	private long _tagsNum;

	@SerializedName("helpsNum")
	private long _helpsNum;

	@SerializedName("isResolved")
	private boolean _isResolved;

	@SerializedName("isCanceled")
	private boolean _isCanceled;

	@SerializedName("resolvedHelpId")
	private long _resolvedHelpId;

	@SerializedName("resolvedUserId")
	private long _resolvedUserId;
	
	

	public long getId()
	{
		return this._id;
	}
	
	public long getUserId()
	{
		return this._userId;
	}
	
	public void setUserId(long userId)
	{
		if(userId < 0) {
			throw new ApiException("userId must be unsigned");
		} else if(userId == 0) {
			throw new ApiException("userId must be set");
		}
		
		this._userId = userId;
	}
	
	public Date getCreateTime()
	{
		return new Date(this._createTime * 1000);
	}
	
	public long getCategoryId()
	{
		return this._categoryId;
	}
	
	public void setCategoryId(long categoryId)
	{
		if(categoryId < 0) {
			throw new ApiException("categoryId must be unsigned");
		}
		this._categoryId = categoryId;
	}
	
	public String getContent()
	{
		return this._content;
	}
	
	public void setContent(String content)
	{
		this._content = content;
	}
	
	public String getContentShort()
	{
		return this._shortContent;
	}
	
	public STATUS getStatus()
	{
		switch(this._status) {
		case 0:
			return STATUS.OPEN;
		case -1:
			return STATUS.CANCELED;
		case 10:
			return STATUS.RESOLVED;
			
		default:
			throw new ApiException("The status " + this._status + " is unknown");
		}
	}
	
	public void setStatus(STATUS status)
	{
		if(status == STATUS.OPEN)
			this._status = 0;
		else if(status == STATUS.CANCELED)
			this._status = -1;
		else if(status == STATUS.RESOLVED)
			this._status = 10;
		else 
			throw new ApiException("The status " + status + " is unknown");
	}
	
	public Date getLastChangeTime()
	{
		return new Date(this._lastChangeTime * 1000);
	}
	
	public long getTagsNum()
	{
		return this._tagsNum;
	}
	
	public long getHelpsNum()
	{
		return this._helpsNum;
	}
	
	public boolean isResolved()
	{
		return this._isResolved;
	}
	
	public boolean isCanceled()
	{
		return this._isCanceled;
	}
	
	public long getResolvedHelpId()
	{
		return this._resolvedHelpId;
	}
	
	public long getResolvedUserId()
	{
		return this._resolvedUserId;
	}
	
	public String toString()
	{
		return "Wish[" + this._id + "]";
	}
	
	public static String statusToString(STATUS status){
		
		if(status == STATUS.OPEN)
			return "OPEN";
		else if(status == STATUS.CANCELED)
			return "CANCELED";
		else if(status == STATUS.RESOLVED)
			return "RESOLVED";
		else 
			throw new ApiException("The status " + status + " is unknown");
	}

	
}
